
package dk.unet.android.ll11;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 *
 * @author Nicolai Willems
 */
public class MainActivity extends Activity {

    private class ClickListener implements OnClickListener {
        private Class<? extends Activity> starter = null;
        
        public ClickListener(Class<? extends Activity> toStart){
            this.starter = toStart;
        }

        public void onClick(View v){
            Intent intent = new Intent(MainActivity.this, starter);
            MainActivity.this.startActivity(intent);
        }
    }

    private OnClickListener campInfoListener = new ClickListener(CampInfoActivity.class);
    private OnClickListener feedListener = new ClickListener(FeedActivity.class);
    private OnClickListener gamesListener = new ClickListener(GamesActivity.class);
    private OnClickListener infoListener = new ClickListener(InfoActivity.class);
    private OnClickListener mapsListener = new ClickListener(MapsActivity.class);
    private OnClickListener matchListener = new ClickListener(MatchActivity.class);

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        // ToDo add your GUI initialization code here
        this.setContentView(R.layout.main);
        
        this.setListener(R.id.btnCampInfo, campInfoListener);
        this.setListener(R.id.btnFeed, feedListener);
        this.setListener(R.id.btnGames, gamesListener);
        this.setListener(R.id.btnInfo, infoListener);
        this.setListener(R.id.btnMap, mapsListener);
        this.setListener(R.id.btnMatch, matchListener);
    }

    private void setListener(int ID, OnClickListener listener){
        Log.d("MainActivity", "Setting listener on: "+ID+" =>"+listener.toString());
        Button btn = (Button)findViewById(ID);
        btn.setOnClickListener(listener);
    }
}
